<?php
    $username = $_POST["username"];
    $pwd = $_POST["pwd"];

    if(strlen($username)>0 && strlen($pwd)>0)
    {
        $con = mysql_connect('localhost','root','chenpo');
        if(!$con)
        {
            die('数据库连接有误:'.mysql_error());
        }
        mysql_select_db("reader",$con);
        $sql_selectuser = "select user_id,user_name from user where user_name='".$username."' and user_pwd=password('".$pwd."')";
        $result_selectuser = mysql_fetch_array(mysql_query($sql_selectuser));
        if($result_selectuser[0]!=null)
        {
            session_start();
            $_SESSION["userid"]=$result_selectuser["user_id"];
            $_SESSION["username"]=$result_selectuser["user_name"];
            //echo $_SESSION["userid"];
            $url = "index.php";
            Header("HTTP/1.1 303 See Other");
            Header("Location: $url");
            exit;
        }
    }
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login</title>
    </head>
    <body>
        <div id="login_form">
            <form action="login.php" method="post">
                <ul>
                    <li>用户登录</li>
                    <li>用户名：<input type="text" id="username" name="username" /></li>
                    <li>密码：<input type="password" id="pwd" name="pwd" /></li>
                    <li><input type="submit" value="登录" /></li>
                </ul>
            </form>
        </div>
        <div id="reg">
            <p><a href="user/reg.html">注册用户</a></p>
        </div>
    </body>
</html>